// 2025/11/16
// 课程表

class Solution {
public:
    bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {
        vector<int> cnt(numCourses, 0);
        unordered_map<int, vector<int>> mp;
        for(auto &v : prerequisites)
        {
            cnt[v[0]]++;
            mp[v[1]].emplace_back(v[0]);
        }
        queue<int> ready;
        int finish = 0;
        for(int i = 0; i < numCourses; i++)
        {
            if(cnt[i] == 0)
                ready.emplace(i);
        }
        while(!ready.empty())
        {
            int next = ready.front();
            ready.pop();
            finish++;
            for(auto num : mp[next])
            {
                if(--cnt[num] == 0)
                    ready.emplace(num);
            }
        }
        return finish == numCourses;
    }
};